import { Layout, Menu, Breadcrumb, Dropdown, Button } from 'antd';
import { history, request } from 'umi';
import {
  UserOutlined,
  LineChartOutlined,
  AppstoreOutlined,
  CopyOutlined,
  FieldTimeOutlined,
  LikeOutlined,
  MenuFoldOutlined,
  MenuUnfoldOutlined,
  BellOutlined,
  CalendarOutlined,
  CheckSquareOutlined,
  FileAddOutlined,
  FileSearchOutlined,
  SolutionOutlined,
} from '@ant-design/icons';
import './index.less';
import React from 'react';
import { Link } from 'react-router-dom';
/** 导入用户登录返回数据判断*/
//import user from '@/user';

class SiderDemo extends React.Component {
  state = {
    collapsed: false,
  };

  toggle = () => {
    this.setState({
      collapsed: !this.state.collapsed,
    });
  };

  render() {
    const out = async () => {
      window.localStorage.setItem('userName', '');
    };
    const { SubMenu } = Menu;
    const { Header, Sider, Content } = Layout;
    /**获得用户名称 */
    let token = window.localStorage.getItem('token');
    let userJson = window.localStorage.getItem('userName');
    console.log(userJson);
    // if (!token) {
    //   //history.replace('/');
    // }
    return (
      <Layout>
        <Header className="header">
          {React.createElement(
            this.state.collapsed ? MenuUnfoldOutlined : MenuFoldOutlined,
            {
              className: 'trigger',
              onClick: this.toggle,
            },
          )}
          <h2 className="h2">学生实训考勤管理系统</h2>
          <Link to="" className="tcdl">
            <span id="username">{userJson}</span>
            <Button onClick={out}>退出登录</Button>
          </Link>
        </Header>

        <Layout>
          <Sider
            className="sider"
            trigger={null}
            collapsible
            collapsed={this.state.collapsed}
          >
            <Menu
              className="menu"
              defaultSelectedKeys={['1']}
              // defaultOpenKeys={['sub1']}
              mode="inline"
              inlineCollapsed={this.state.collapsed}
            >
              <Menu.Item key="1" icon={<AppstoreOutlined />}>
                <Link to="/Teacher/Course">项目课程表</Link>
              </Menu.Item>
              <SubMenu key="sub1" icon={<FileAddOutlined />} title="作业管理">
                <Menu.Item key="2" icon={<AppstoreOutlined />}>
                  <Link to="/Teacher/Assignment/Issue/index">下发作业</Link>
                </Menu.Item>
                <Menu.Item key="3" icon={<FileSearchOutlined />}>
                  <Link to="/Teacher/Assignment/Approval/index">作业审批</Link>
                </Menu.Item>
              </SubMenu>
              <Menu.Item key="4" icon={<FieldTimeOutlined />}>
                <Link to="/Teacher/AttendanceRecord/index">考勤记录</Link>
              </Menu.Item>
              <Menu.Item key="5" icon={<CalendarOutlined />}>
                <Link to="/Teacher/Leave/index">请假管理</Link>
              </Menu.Item>
              <Menu.Item key="6" icon={<CheckSquareOutlined />}>
                <Link to="/Teacher/Comprehensive/index">综合打分</Link>
              </Menu.Item>
              <SubMenu
                key="sub2"
                icon={<SolutionOutlined />}
                title="个人信息管理"
              >
                <Menu.Item key="7" icon={<UserOutlined />}>
                  <Link to="/Teacher/Modify/index">修改密码</Link>
                </Menu.Item>
              </SubMenu>
            </Menu>
          </Sider>

          <Content className="content">{this.props.children}</Content>
        </Layout>
      </Layout>
    );
  }
}

export default SiderDemo;
